package com.chushouya.order.constants;


import com.general.framework.core.enums.IEnum;
import com.general.framework.core.exception.Ex;
import org.apache.logging.log4j.util.Strings;

import java.util.Objects;

public enum OrderStatusEnum implements IEnum<Integer> {

    NEW_ORDER(0, "新订单"),
    WAIT_CHECK(1, "待确认"),
    CANCELLED(20, "已取消"),
    CLOSED(21, "已关闭"),
    TIMEOUT(22, "超时关闭"),
    BACKOUT_AUDITING(23, "撤单审核中"),
    BACKOUT_CLOSED(24, "已撤单"),
    CLERK_CANCEL(25, "业务员取消"),
    RETURN_CLOSED(26, "退货关闭"),
    CMCC_CANCEL(27, "店员关闭"),
    CHARGE_CLOSE(28, "退单关闭"),
    WAIT_PICKUP(32, "待取件"),
    WAIT_RECEIVE(30, "待收货"),
    WAIT_QUALITY(31, "待质检"),
    WAIT_ACCEPT(40, "待接单"),
    WAIT_CONFIRM(42, "待确认"),
    WAIT_VISIT(41, "待上门"),
    WAIT_BARGAIN(80, "待议价"),
    WAIT_RETURN(91, "待退货"),
    WAIT_PAY(90, "待打款"),
    COMPLETE(100, "已完成");
    ;
    private Integer value;

    private String desc;


    OrderStatusEnum(Integer value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public static String getDesc(Integer status) {
        for (OrderStatusEnum thisEnum : OrderStatusEnum.values()) {
            if (Objects.equals(thisEnum.value, status)) {
                return thisEnum.desc;
            }
        }
        return Strings.EMPTY;
    }

    public static OrderStatusEnum get(Integer status) {
        for (OrderStatusEnum thisEnum : OrderStatusEnum.values()) {
            if (Objects.equals(thisEnum.value, status)) {
                return thisEnum;
            }
        }
        throw Ex.systemError("未定义的订单类型[{}]", status);
    }

    @Override
    public Integer value() {
        return this.value;
    }

    @Override
    public String named() {
        return this.desc;
    }
}
